/*
 * 
 * Copyright 2011 visual-analysis-of-cancer.
 * This file is part of visual-analysis-of-cancer.
 * 
 * visual-analysis-of-cancer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * visual-analysis-of-cancer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * visual-analysis-of-cancer:
 * An tool to analye the WHO and GLOBOCAN cancer data.
 * http://code.google.com/p/visual-analysis-of-cancer/
 * 
 * 
 * 
 * Authors: Erik Sniegula, Johannes Dahlke
 * 
 * Module:  Programming in Processing for Visual Analytics
 * Group:   20
 * 
 * Created: Aug. 2011
 * Version: 1.0
 *
 */
 




package de.fuberlin.processing.who.cancer.controlp5ex;

import processing.core.PApplet;
import processing.core.PFont;
import controlP5.ControlFont;
import controlP5.ControlP5;
import controlP5.Controller;
import controlP5.ControllerGroup;
import controlP5.Label;
import controlP5.Textlabel;
import de.fuberlin.processing.who.cancer.gui.healthgraph.TooltipPropertiedControllerInterface;
import de.fuberlin.processing.who.cancer.utils.Test;


public class LinkLabel extends Controller {
	

	private float left;
	private float top;
	private String labelString;
	private String url;
	private PFont font;
	private int textColor;
	private Label label;
	private String tooltip = null;
	private boolean printCenter;
	private int fontSize;
	
	private String target = "_blank";
	
	
	public LinkLabel( final ControlP5 theControlP5, final ControllerGroup theParent, String theName, String theLabel, String theUrl, float theX, float theY, int theWidth, int theHeight, int theColor, PFont theFont, int fontSize, boolean printCenter) {
		super( theControlP5, theParent, theName, theX, theY, theWidth, theHeight);
		this.left = theX;
		this.top = theY;
		this.labelString = theLabel;
		this.url = theUrl;
		this.textColor = theColor;
		this.font = theFont;
		this.printCenter = printCenter;
		this.fontSize = fontSize;
		label = new Label( theLabel);
		label.setFont( new ControlFont( theFont));
		label.setFontSize( fontSize);
	}
	 
	
	@Override
	public void draw( PApplet p) {
		p.pushStyle();
		p.textFont( font, fontSize);
		float labelWidth = p.textWidth( labelString);
		float labelHeight = label.getLineHeight();
		
		float offsetX = left;
		float offsetY = top;
		
		if ( printCenter) {
			offsetX = left + ( width - labelWidth) / 2;
			offsetY = top + ( height -labelHeight) / 2;
		}
		label.draw( p, (int) offsetX, (int) offsetY);
		p.popStyle();
	}
	
	public void setTarget( String target) {
		this.target = target;
	}
	
	public void setTooltip( String tooltip) {
	  this.tooltip = tooltip;
	  registerTooltip( tooltip);
	}
	
	@Override
	protected void mousePressed() {
		controlP5.papplet.link( url, target);
		super.mousePressed();
	}

	@Override
	public Controller setValue( float theValue) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void setLabelColor( int color) {
		label.setColor( color);
	}

	
}
